﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Threading.Thread;
using static System.Console;

namespace Project_5
{
    /// <summary>
    /// 5.3 在lambda 表达式中使用await 
    /// </summary>
    public class Unit_5_03
    {
        public static void Go()
        {
            Task t = AsyncProcessing();
            t.Wait();
        }

        static async Task AsyncProcessing()
        {
            Func<string, Task<string>> asyncLambda = async name =>
            {
                await Task.Delay(TimeSpan.FromSeconds(2));
                return $"Task {name} is running on a thread id {CurrentThread.ManagedThreadId}." +
                       $"是否是线程池中的线程:{CurrentThread.IsThreadPoolThread}";
            };
            string result = await asyncLambda("async lambda");

            WriteLine(result);
        }
    }
}
